{include file="public/head" /}
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>后台管理</cite></a>
        <a><cite>物业管理系统</cite></a>
        <a><cite>微信管理</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{:url('userauth')}">
          <input type="hidden" value="{$deviceid}" name="deviceid"/>

          <input class="layui-input" placeholder="姓名" name="name1" value="{if isset($name1)}{$name1}{/if}">

          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn " onclick="accredit()"><i class="layui-icon"></i>授权</button>
        <button class="layui-btn layui-btn-danger" onclick="cancalaccredit()">取消授权</button>
      </xblock>
      <table class="layui-table" id="table">
        <thead  style="text-align:center;">
          <tr>
            <th style="width: 4%;text-align:center;">
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align:center;">小区名称</th>
            <th style="text-align:center;">组团</th>
            <th style="text-align:center;">楼栋</th>
            <th style="text-align:center;">单元</th>
            <th style="text-align:center;">房号</th>
            <th style="text-align:center;">楼层号</th>
            <th style="text-align:center;">姓名</th>
            <th style="text-align:center;">绑定码</th>
            <th style="text-align:center;">openid</th>


            <!-- 8 -->
          </tr>
        </thead>
        <tbody style="text-align:center;">
          {foreach $list as $val}
          <tr>
            <td>
                <div class="layui-unselect layui-form-checkbox {if $val.authstatus=='1'} layui-form-checked {/if} "lay-skin="primary" data-id='{$val.id}' ><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$val.community_name}</td>
            <td>{$val.group}</td>
            <td>{$val.building}幢</td>
            <td>{$val.unit}单元</td>
            <td>{$val.room}室</td>
            <td>{$val.wiegand}</td>
            <td>{$val.name}</td>
            <td>{$val.bind_code}</td>
            <td>{$val.openid}</td>

          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div id="page">
            {$userlist->render()}
        </div>
      </div>

    </div>
    <script>
        function accredit(){
            var datas = $('#table tbody td .layui-form-checked')
            var ids = []
            datas.each(function(index, element){
                var id = $(this).data('id')
                ids.push(id)
            })

            var userids = ids.join(',');
            var count = ids.length
            if(count=="0"){
                alert("请选择要授权的人员");
                return false;
            }
            var deviceid='{$deviceid}';
            var url='{:url("useraccredit")}?deviceid='+deviceid+"&userids="+userids;
            window.location.href = url;return;
            $.post('{:url("useraccredit")}', {deviceid: deviceid,userids:userids}, function(r){
                if(r.code=="0"){
                    alert('人员授权成功');
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭当前页
                    //window.parent.location.replace(location.href)//刷新父级页面

                    //window.parent.location.reload();
                }

            })
        }
        function cancalaccredit(){
            var datas = $('#table tbody td .layui-form-checked')
            var ids = []
            datas.each(function(index, element){
                var id = $(this).data('id')
                ids.push(id)
            })

            var userids = ids.join(',');
            var count = ids.length
            if(count=="0"){
                alert("请选择要取消授权的人员");
                return false;
            }
            var deviceid='{$deviceid}';
            var url='{:url("usercancelaccredit")}?deviceid='+deviceid+"&userids="+userids;
            window.location.href = url;return;
            $.post('{:url("usercancalaccredit")}', {deviceid: deviceid,userids:userids}, function(r){
                if(r.code=="0"){
                    alert('人员授权成功');
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);//关闭当前页
                    //window.parent.location.replace(location.href)//刷新父级页面

                    //window.parent.location.reload();
                }

            })
        }
    </script>
    
    <script>
        layui.use(['form'], function() {
            var form = layui.form
            form.on('select(community_id)', function(f){
                var url = "{:url('fetchdata')}"
                $.post(url, {community_id: f.value, type: 1}, function(data) {
                    $('#group').html("")
                    var option = "<option value=''>所有组团</option>"
                    $('#group').append(option)
                    for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                    $('#group').append(option)
                    }
                    
                    form.render('select')
                })
                
                $('#community_id').data('community_id', f.value)
            })

            form.on('select(group)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community
                var url = "{:url('fetchdata')}"
                $.post(url, {community_id: community_id, group: f.value, type: 2}, function(data) {
                    $('#building').html("")
                    var option = "<option value=''>所有楼栋</option>"
                    $('#building').append(option)
                    for (var i = 0; i < data.length; i++) {
                        option = "<option value='" + data[i] + "'>" + data[i] + "幢</option>"
                        $('#building').append(option)
                    }
                    $('#group').data('group', f.value)
                    form.render('select')
                })
            })
    
            form.on('select(building)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community

                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var url = "{:url('fetchdata')}"
                $.post(url, {building: f.value, community_id: community_id, group: group, type: 3}, function(data) {
                $('#unit').html("")
                var option = "<option value=''>所有单元</option>"
                $('#unit').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "单元</option>"
                    $('#unit').append(option)
                }
                $('#building').data('building', f.value)
                form.render('select')
                })
            })
    
            form.on('select(unit)', function(f){
                var data_community = $('#community_id').data('community_id')
                var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
                var community_id = typeof data_community === 'undefined' ? get_community : data_community

                var data_group = $('#group').data('group')
                var get_group = "<?php if (isset($group)) { echo $group;}?>"
                var group = typeof data_group === 'undefined' ? get_group : data_group

                var data_building = $('#building').data('building')
                var get_building = "<?php if (isset($building)) { echo $building;}?>"
                var building = typeof data_building === 'undefined' ? get_building : data_building
        
                var url = "{:url('fetchdata')}"
                $.post(url, {unit: f.value, community_id: community_id, group: group, building: building, type: 4}, function(data) {
                $('#room').html("")
                var option = "<option value=''>所有房间</option>"
                $('#room').append(option)
                for (var i = 0; i < data.length; i++) {
                    option = "<option value='" + data[i] + "'>" + data[i] + "室</option>"
                    $('#room').append(option)
                }
                $('#unit').data('unit', f.value)
                form.render('select')
                })
            })
    
        })
    </script>

    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>

  </body>

</html>